package com.webshop.servlet;
import com.webshop.Dao.PageDao;
import com.webshop.domain.Items;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

public class GetPageServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String id = req.getParameter("id");
        if(id==null || (Integer.parseInt(id)<0)){
            resp.sendRedirect("index.jsp");
            return;
        }
        String pclass = Items.allclass.get(Integer.parseInt(id));
        req.setAttribute("pclass",pclass);
        List<Items> items = new PageDao().getItems(pclass);
        req.setAttribute("items",items);
        req.getRequestDispatcher("items.jsp").forward(req,resp);
        return;
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
